package app.netant.book.to59;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class To59Detail extends BaseDetail {

	public To59Detail(String netSite) {
		super(netSite);
		this.preHref = "https://www.59to.net";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select(".main #centerl #content .wrap #main .main .main_left .lianzai .lianzai_right h1");
		if(parts.size()>0){
			String title = parts.get(0).text().trim();
			Elements spans = parts.get(0).select("span");
			if(spans.size()>0){
				String plus = spans.get(0).text().trim();
				if(plus.length()>0){
					title = title.substring(0, title.length()-plus.length()).trim();
				}
			}
			System.out.println("【Title】:"+title);	
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
		
		Elements parts1 = this.select(".main #centerl #content .wrap #main .main .main_left .lianzai .lianzai_right p.author");
		if(parts1.size()>0){
			String writer = parts1.get(0).text().trim();
			int idx = writer.indexOf("：");
			if(idx>0){
				writer = writer.substring(idx+1).trim();
			}
			System.out.println("【Writer】:"+writer);
			this.entity.setNovelWriter(writer);
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select(".main #centerl #content .wrap #main .main .main_left .lianzai .lianzai_right .textbox");
		if(parts.size()>0){
			String tags = parts.get(0).text();
			this.splitTags(tags, true);
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select(".main #centerl #content .wrap #main .main .main_left .lianzai .lianzai_right .container");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select(".main #centerl #content .wrap #main .main .main_left .lianzai .lianzai_left .score1 .operat2 a.xiazai");
		if(parts.size()>0){
			String href = parts.get(0).attr("href");
			if(href.startsWith("/")){
				href = this.preHref + href;
			}
			System.out.println("【Href】:"+href);
			this.entity.setDownPath(href);
		}
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select(".main #centerl #content .wrap #main .navv a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		To59Detail detail = new To59Detail("https://www.59to.net/info/221/221892.html");
		detail.test();
	}



}
